<template>
	<view class="my-card-health">
		<u-section title="就诊凭条" :right="false" :bold='false' :line-color='themeColorLight' color="#000000"></u-section>
		<view class="my-card-health-code">
			<tkiQrcode ref="qrcode" onval :val="qrCode" :size="350"
				:load-make="true" :show-loading="false"></tkiQrcode>
		</view>
		<u-section title="就诊人信息" :right="false" :bold='false' :line-color='themeColorLight' color="#000000"></u-section>
		<view class="my-card-health-user">
			<view class="card-row"> <label>姓名：</label>{{routeParams.name}}</view>
			<view class="card-row"> <label>身份证号：</label>{{routeParams.cardNo}}</view>
			<view class="card-row"> <label>电话：</label>{{routeParams.phoneNumber}}</view>
		</view>
		<view class="my-card-health-btn">
			<view class="theme-light-btn" v-if="routeParams.loginStatus===2" @click="onDefault(routeParams.patId)">默认当前卡</view>
			<view class="wihte" @click="onCancle(routeParams.patId)">解除绑定</view>
			<view class="wihte" @click="onEdit(routeParams.patId)">修改个人信息</view>
			<!-- #ifndef MP-ALIPAY -->
			<view class="wihte" v-if="isTXHealthCard">添加到卡包</view>
			<!-- #endif -->
		</view>
		<Load :load="load"></Load>
	</view>
</template>

<script>
	import { mapGetters, mapActions } from 'vuex'
	import { themeColorLight } from '@/static/js/theme.js'
	import tkiQrcode from '@/components/QrCode/tki-qrcode.vue'
	import Load from '@/components/Load/index.vue'
	export default {
		components:{ tkiQrcode, Load },
		data() {
			return {
				themeColorLight,
				routeParams:'',
				qrCode:'3',
				load:true
			}
		},
		computed:{
			...mapGetters(['healthCardType'])
		},
		onLoad(op) {
			let res = JSON.parse(op.params)
			this.qrCode = res.qrCodeText||''
			this.routeParams = res
			this.load = false
		},
		methods: {
			...mapActions(['changeUser','userLogout', 'userDetail']),
			onDefault(patId){
				if(patId){
					this.load = true
					this.changeUser(patId).then(()=> {
						this.load = false
						this.$u.toast('设置默认就诊人成功');
					}).catch(e => this.load = false)
				}
			},
			onCancle(patId){
				if(patId){
					this.load = true
					this.userLogout(patId).then(()=> {
						this.load = false
						this.$u.toast('解绑成功');
					}).catch(e => this.load = false)
				}
			},
			onEdit(patId){
				this.load = true
				this.userDetail(patId).then((data)=> {
					this.load = false
					let res = JSON.stringify(data||'')
					uni.setStorageSync('editPageTo','/pages/Personal/MyCard/index')
					uni.navigateTo({
						url:'/pages/Login/register?editInfo=' + res
					})
				}).catch(e => this.load = false)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.my-card-health{
		padding: 20rpx 30rpx;
		height: calc(100vh);
		overflow: scroll;
		background-color: $uni-bg-color;
		&-code{
			padding: 20rpx 0;
		}
		&-user{
			padding: 20rpx;
		}
		&-btn{
			margin-bottom: 40rpx;
			>view{
				height: 90rpx;
				margin-top: 20rpx;
			}
			>.wihte{
				display: flex;
				justify-content: center;
				align-items: center;
				border: 1px solid $theme-color-light;
				color: $theme-color-light;
				font-size: 34rpx;
				border-radius:12rpx;
			}
		}
	}
</style>